package com.example.feifei.newproject;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.VideoView;

import com.example.feifei.adapter.ChildPagerAdapter;
import com.example.feifei.adapter.ScrollPagerAdapter;
import com.example.feifei.utils.MyScrollView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by feifei on 2017/7/6.
 */

public class ScrollViewActivity extends Activity {

    private MyScrollView my_scrollview;
    private View show_view;
    private ViewPager scroll_viewpager;

    ScrollPagerAdapter scrollPagerAdapter;
    ChildPagerAdapter childPagerAdapter;

    List<View> listViews;
    List<View> child_listViews;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_scrollview);
        initView();

    }


    private void initView(){
        my_scrollview = (MyScrollView) this.findViewById(R.id.my_scrollview);
        show_view = this.findViewById(R.id.show_view);
        scroll_viewpager = (ViewPager) this.findViewById(R.id.scroll_viewpager);
        my_scrollview.setScrollViewListener(new MyScrollView.OnScrollViewListener() {
            @Override
            public void onScrollView(int scrollY) {
                if(scrollY<800){
                    show_view.setVisibility(View.GONE);
                }else if(scrollY>=800&&scrollY<=1000){
                    show_view.setVisibility(View.VISIBLE);
                    //设置Alpha值在0-255之间，有一个渐变的效果
                    show_view.getBackground().setAlpha((int)((scrollY-800)*(255/200)));
                }else{
                    show_view.setVisibility(View.VISIBLE);
                }
            }
        });
        initPagerData();
    }

    private void initPagerData(){
        listViews = new ArrayList<>();
        View view_father1 = LayoutInflater.from(this).inflate(R.layout.pager_childview,null);

            ViewPager child_pager = (ViewPager) view_father1.findViewById(R.id.pager_child);
            child_listViews = new ArrayList<>();
            View child_view1 = LayoutInflater.from(this).inflate(R.layout.item_childview,null);
           child_listViews.add(child_view1);
            View child_view2 = LayoutInflater.from(this).inflate(R.layout.item_childview,null);
            child_listViews.add(child_view2);
            View child_view3 = LayoutInflater.from(this).inflate(R.layout.item_childview,null);
            child_listViews.add(child_view3);
            childPagerAdapter = new ChildPagerAdapter(child_listViews);
            child_pager.setAdapter(childPagerAdapter);

        listViews.add(view_father1);
        View view_father2 = LayoutInflater.from(this).inflate(R.layout.item_father_view,null);
        listViews.add(view_father2);
        View view_father3 = LayoutInflater.from(this).inflate(R.layout.item_father_view,null);
        listViews.add(view_father3);
        scrollPagerAdapter = new ScrollPagerAdapter(listViews);
        scroll_viewpager.setAdapter(scrollPagerAdapter);


    }
}
